--[[

	Copyright (c) 2011-2020 baby-bus.com

	TODO:   TouchLayerName
	Author: DemonYao
	Date:   2020.09.21
 
	http://www.babybus.com/ 

]] 




--------------------------
-- 引入命名空间
--------------------------




--[[
	类
--]]


local M = classLayerTouch("Main")




--------------------------
-- 构造函数
--------------------------

function M:ctor(params)
	-- [超类调用]
	M.super.ctor(self, params)
	-- [本类调用]

end

--------------------------
-- 渲染
--------------------------

function M:onRender()
	-- [超类调用]
	M.super.onRender(self)
	-- 加载背景图
	local bg = U.loadBg("background.png"):to(self)
	
	-- [本类调用]
	-- 加载节点
	self:loadNodes()
	-- local DragonBone = import("bbframework.client.si.DragonBone")

	-- DragonBone.addFile("zyqiqi_outputX4/zyqiqi")
	-- local node = DragonBone.createArmature("zyqiqi")
	-- dump(node:getContentSize())
	-- node:setPosition(480, 270)
	-- node:addTo(self)
	-- local size = node:getContentSize()

	-- tool:loadHelpRect({
	-- 	node = node,
	-- 	pos = cc.p(0, 0),
	-- 	size = cc.size(size.width, size.height),--armatureDisplay:getContentSize(),
	-- 	anchorPoint = cc.p(0, 0)
	-- }):opacity(200)	

	-- self:createNode("Bone", {
	-- 	file			= "zyqiqi_outputX4/zyqiqi",
	-- 	armatureName    = "zyqiqi",
	-- 	animName		= "huxi"
	-- }):p(480, 270):to(self)
end

-- 加载节点
function M:loadNodes()

	-- dragonBones.CCFactory:loadDragonBonesData("mecha_1004d/mecha_1004d_ske.json", "test")
	-- dragonBones.CCFactory:loadTextureAtlasData("mecha_1004d/mecha_1004d_tex.json", "test")
	-- local armatureDisplay = dragonBones.CCFactory:buildArmatureDisplay("mecha_1004d")
	-- CCNodeExtend.extend(armatureDisplay)
	-- dump(armatureDisplay:getContentSize())
	-- local boundingBox = armatureDisplay:getBoundingBox()
	-- -- armatureDisplay:setContentSize(cc.size(boundingBox.width, boundingBox.height))
	-- armatureDisplay:anchor(cc.p(0.5, 0.5))
	-- armatureDisplay:p(480, 270)
	-- armatureDisplay:to(self):bindTouchLocate()
	-- armatureDisplay:getAnimation():play("idle")

	-- tool:loadHelpRect({
	-- 	node = armatureDisplay,
	-- 	pos = cc.p(0, 0),
	-- 	size = cc.size(armatureDisplay:cw(), armatureDisplay:ch()),--armatureDisplay:getContentSize(),
	-- 	anchorPoint = cc.p(0, 0)
	-- }):opacity(200)	

	


	-- self:createNode("dragonBone", {
	-- 	dragonBonesDataFile 	    = "mecha_1002_101d_show/mecha_1002_101d_show_ske.json",
	-- 	dragonBonesTexFile 		    = "mecha_1002_101d_show/mecha_1002_101d_show_tex.json",
	-- 	armatureName				= "mecha_1002_101d",
	-- 	animName					= "idle"
	-- }):pc():to(self)

	self:createNode("dragonBone", {
		dragonBonesDataFile 	    = "mecha_1004d/mecha_1004d_ske.json",
		dragonBonesTexFile 		    = "mecha_1004d/mecha_1004d_tex.json",
		armatureName				= "mecha_1004d",
		animName					= "idle"
	}):pc():to(self)

	-- self.robot = self:createNode("dragonBone", {
	-- 	dragonBonesDataFile = "mecha_1502b/mecha_1502b_ske.json",
	-- 	dragonBonesTexFile  = "mecha_1502b/mecha_1502b_tex.json",
	-- 	armatureName        = "mecha_1502b",
	-- 	animName			= "idle"
	-- }):pc():to(self)

	-- self:createArmature(
	-- 	"mecha_1002_101d_show/mecha_1002_101d_show_ske.json", 
	-- 	"mecha_1002_101d_show/mecha_1002_101d_show_tex.json", 
	-- 	"mecha_1002_101d", 
	-- 	"idle"
	-- )

	-- self:createArmature(
	-- 	"mecha_1004d/mecha_1004d_ske.json", 
	-- 	"mecha_1004d/mecha_1004d_tex.json", 
	-- 	"mecha_1004d", 
	-- 	"idle"
	-- )
end

-- 创建骨骼
function M:createArmature(dragonBonesDataFile, dragonBonesTexFile, armatureName, animName)
	dragonBones.CCFactory:loadDragonBonesData(dragonBonesDataFile, "test")
	dragonBones.CCFactory:loadTextureAtlasData(dragonBonesTexFile, "test")
    local armatureDisplay = dragonBones.CCFactory:buildArmatureDisplay(armatureName)
    CCNodeExtend.extend(armatureDisplay):rotation(15)
    -- 设置节点大小
    self:setContentSize(cc.size(armatureDisplay:cw(), armatureDisplay:ch()))

    armatureDisplay:anchor(cc.p(0.5, 0.5))
    local size = armatureDisplay:getContentSize()
    local anchor = armatureDisplay:getAnchorPoint()
	dump(anchor)
    armatureDisplay:to(self):pc()

    if animName then
        armatureDisplay:getAnimation():play(animName)
    end
end



-- 加载渲染以外的其他操作
function M:onEnterTransitionFinish()

end




--------------------------
-- 触控
-------------------------- 

function M:onTouchBegan(x, y, touches)
	--  触控有效
	return true 
end

function M:onTouchMoved(x, y, touches)
	--   
end

function M:onTouchEnded(x, y, touches)
	--  
end



--------------------------
-- 功能函数
--------------------------




--------------------------
-- 属性
--------------------------




--------------------------
-- 父类重写
--------------------------




----------------------------------------------------
-- 析构
--------------------------

function M:onDestructor()
	-- [超类调用]
	M.super.onDestructor(self)
	-- [本类调用]

end








return M






